package cn.iocoder.yudao.module.shop.controller.admin.userholiday;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.shop.controller.admin.userholiday.vo.*;
import cn.iocoder.yudao.module.shop.dal.dataobject.userholiday.ShopUserHolidayDO;
import cn.iocoder.yudao.module.shop.convert.userholiday.ShopUserHolidayConvert;
import cn.iocoder.yudao.module.shop.service.userholiday.ShopUserHolidayService;

@Tag(name = "管理后台 - 艾灸师请假")
@RestController
@RequestMapping("/shop/user-holiday")
@Validated
public class ShopUserHolidayController {

    @Resource
    private ShopUserHolidayService userHolidayService;

    @PostMapping("/create")
    @Operation(summary = "创建艾灸师请假")
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:create')")
    public CommonResult<Long> createUserHoliday(@Valid @RequestBody ShopUserHolidayCreateReqVO createReqVO) {
        return success(userHolidayService.createUserHoliday(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新艾灸师请假")
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:update')")
    public CommonResult<Boolean> updateUserHoliday(@Valid @RequestBody ShopUserHolidayUpdateReqVO updateReqVO) {
        userHolidayService.updateUserHoliday(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除艾灸师请假")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:delete')")
    public CommonResult<Boolean> deleteUserHoliday(@RequestParam("id") Long id) {
        userHolidayService.deleteUserHoliday(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得艾灸师请假")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:query')")
    public CommonResult<ShopUserHolidayRespVO> getUserHoliday(@RequestParam("id") Long id) {
        ShopUserHolidayDO userHoliday = userHolidayService.getUserHoliday(id);
        return success(ShopUserHolidayConvert.INSTANCE.convert(userHoliday));
    }

    @GetMapping("/list")
    @Operation(summary = "获得艾灸师请假列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:query')")
    public CommonResult<List<ShopUserHolidayRespVO>> getUserHolidayList(@RequestParam("ids") Collection<Long> ids) {
        List<ShopUserHolidayDO> list = userHolidayService.getUserHolidayList(ids);
        return success(ShopUserHolidayConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得艾灸师请假分页")
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:query')")
    public CommonResult<PageResult<ShopUserHolidayRespVO>> getUserHolidayPage(@Valid ShopUserHolidayPageReqVO pageVO) {
        PageResult<ShopUserHolidayDO> pageResult = userHolidayService.getUserHolidayPage(pageVO);
        return success(ShopUserHolidayConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出艾灸师请假 Excel")
    @PreAuthorize("@ss.hasPermission('shop:user-holiday:export')")
    @OperateLog(type = EXPORT)
    public void exportUserHolidayExcel(@Valid ShopUserHolidayExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ShopUserHolidayDO> list = userHolidayService.getUserHolidayList(exportReqVO);
        // 导出 Excel
        List<ShopUserHolidayExcelVO> datas = ShopUserHolidayConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "艾灸师请假.xls", "数据", ShopUserHolidayExcelVO.class, datas);
    }

}
